package com.zhangxiaofanfan.hotcode.fourth.third;

/**
 *
 * @date 2024-07-13 03:14:13
 * @author zhangxiaofanfan
 */
public class HotCode077 {
    public static void main(String[] args) {
        HotCode077 hotCode = new HotCode077();
        int[] prices = {7,1,5,3,6,4};
        System.out.println(hotCode.maxProfit(prices));
    }

    public int maxProfit(int[] prices) {
        int profit = 0, minPrice = prices[0];
        for (int i = 1; i < prices.length; i++) {
            profit = Math.max(profit, prices[i] - minPrice);
            minPrice = Math.min(minPrice, prices[i]);
        }
        return profit;
    }

}
